package Code.Test;

import java.util.Random;

/*打乱数组中的数据
需求;定义一个数组，存入1-5，要求打乱数组中的所有数据顺序

 */
public class Test5 {
    public static void main(String[] args) {
        int[] arr = {1,2,3,4,5};

        Random random = new Random();

        for (int i = 0; i < arr.length/2; i++) {
            int index = random.nextInt(arr.length);
            int temp = arr[i];
            arr[i] = arr[index];
            arr[index] = temp;
        }

        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]+" ");
        }
    }
}
